using System;
using System.Data;
using System.Data.Common;
using System.Configuration;
using System.Data.SqlClient;

using SIS.ENT;


namespace SIS.DAL
{
    /// <summary>
    /// The GuardianProfileTableDB class is responsible for interacting with the database to retrieve and store information
    /// about GuardianProfileTable objects.
    /// </summary>
    public class GuardianProfileTableDB
    {
        #region "Public Methods"

        /// <summary>
        /// Gets an instance of GuardianProfileTable from the underlying datasource.
        /// </summary>
        /// <param name="guardianProfileKey">The unique GuardianProfileKey of the GuardianProfileTable in the database.</param>
        /// <returns>An GuardianProfileTable when the GuardianProfileKey was found in the database, or null otherwise.</returns>
        public static GuardianProfileTable GetItem(int guardianProfileKey)
        {
            GuardianProfileTable myGuardianProfileTable = null;
            using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sis.dbconn"].ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("sprocGuardianProfileTableSelectSingleItem", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;
                    myCommand.Parameters.AddWithValue("@guardianProfileKey", guardianProfileKey);

                    myConnection.Open();
                    using (SqlDataReader myReader = myCommand.ExecuteReader())
                    {
                        if (myReader.Read())
                        {
                            myGuardianProfileTable = FillDataRecord(myReader);
                        }
                        myReader.Close();
                    }
                    myConnection.Close();
                }
                return myGuardianProfileTable;
            }
        }

        /// <summary>
        /// Gets an instance of GuardianProfileTable from the underlying datasource.
        /// </summary>
        /// <param name="UserAccountKey">The unique UserAccountKey of the GuardianProfileTable in the database.</param>
        /// <returns>An GuardianProfileTable when the UserAccountKey was found in the database, or null otherwise.</returns>
        public static GuardianProfileTable GetItemByUserAccountKey(int UserAccountKey)
        {
            GuardianProfileTable myGuardianProfileTable = null;
            using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sis.dbconn"].ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("sprocGuardianProfileTableSelectSingleItemByUserAccountKey", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;
                    myCommand.Parameters.AddWithValue("@UserAccountKey", UserAccountKey);

                    myConnection.Open();
                    using (SqlDataReader myReader = myCommand.ExecuteReader())
                    {
                        if (myReader.Read())
                        {
                            myGuardianProfileTable = FillDataRecord(myReader);
                        }
                        myReader.Close();
                    }
                    myConnection.Close();
                }
                return myGuardianProfileTable;
            }
        }

        /// <summary>
        /// Returns a list with GuardianProfileTable objects.
        /// </summary>
        /// <returns>A generics List with the GuardianProfileTable objects.</returns>
        public static GuardianProfileTableList GetList()
        {
            GuardianProfileTableList tempList = new GuardianProfileTableList();
            using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sis.dbconn"].ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("sprocGuardianProfileTableSelectList", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    myConnection.Open();
                    using (SqlDataReader myReader = myCommand.ExecuteReader())
                    {
                        if (myReader.HasRows)
                        {
                            while (myReader.Read())
                            {
                                tempList.Add(FillDataRecord(myReader));
                            }
                        }
                        myReader.Close();
                    }
                }
            }
            return tempList;
        }

        /// <summary>
        /// Returns a list with GuardianProfileTable objects.
        /// </summary>
        /// <returns>A generics List with the GuardianProfileTable objects.</returns>
        public static GuardianProfileTableList GetListByBloodGroupCode(short BloodGroupCode)
        {
            GuardianProfileTableList tempList = new GuardianProfileTableList();
            using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sis.dbconn"].ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("sprocGuardianProfileTableSelectListByBloodGroupCode", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;
                    myCommand.Parameters.AddWithValue("@bloodGroupCode", BloodGroupCode);
                    myConnection.Open();
                    using (SqlDataReader myReader = myCommand.ExecuteReader())
                    {
                        if (myReader.HasRows)
                        {
                            while (myReader.Read())
                            {
                                tempList.Add(FillDataRecord(myReader));
                            }
                        }
                        myReader.Close();
                    }
                }
                return tempList;
            }
        }

        /// <summary>
        /// Returns a list with GuardianProfileTable objects.
        /// </summary>
        /// <returns>A generics List with the GuardianProfileTable objects.</returns>
        public static GuardianProfileTableList GetListByMartialStatusCode(short MartialStatusCode)
        {
            GuardianProfileTableList tempList = new GuardianProfileTableList();
            using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sis.dbconn"].ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("sprocGuardianProfileTableSelectListByMartialStatusCode", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;
                    myCommand.Parameters.AddWithValue("@martialStatusCode", MartialStatusCode);
                    myConnection.Open();
                    using (SqlDataReader myReader = myCommand.ExecuteReader())
                    {
                        if (myReader.HasRows)
                        {
                            while (myReader.Read())
                            {
                                tempList.Add(FillDataRecord(myReader));
                            }
                        }
                        myReader.Close();
                    }
                }
                return tempList;
            }
        }

        /// <summary>
        /// Returns a list with GuardianProfileTable objects.
        /// </summary>
        /// <returns>A generics List with the GuardianProfileTable objects.</returns>
        public static GuardianProfileTableList GetListByNationalityCode(short NationalityCode)
        {
            GuardianProfileTableList tempList = new GuardianProfileTableList();
            using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sis.dbconn"].ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("sprocGuardianProfileTableSelectListByNationalityCode", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;
                    myCommand.Parameters.AddWithValue("@nationalityCode", NationalityCode);
                    myConnection.Open();
                    using (SqlDataReader myReader = myCommand.ExecuteReader())
                    {
                        if (myReader.HasRows)
                        {
                            while (myReader.Read())
                            {
                                tempList.Add(FillDataRecord(myReader));
                            }
                        }
                        myReader.Close();
                    }
                }
                return tempList;
            }
        }

        /// <summary>
        /// Returns a list with GuardianProfileTable objects.
        /// </summary>
        /// <returns>A generics List with the GuardianProfileTable objects.</returns>
        public static GuardianProfileTableList GetListByRaceCode(short RaceCode)
        {
            GuardianProfileTableList tempList = new GuardianProfileTableList();
            using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sis.dbconn"].ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("sprocGuardianProfileTableSelectListByRaceCode", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;
                    myCommand.Parameters.AddWithValue("@raceCode", RaceCode);
                    myConnection.Open();
                    using (SqlDataReader myReader = myCommand.ExecuteReader())
                    {
                        if (myReader.HasRows)
                        {
                            while (myReader.Read())
                            {
                                tempList.Add(FillDataRecord(myReader));
                            }
                        }
                        myReader.Close();
                    }
                }
                return tempList;
            }
        }

        /// <summary>
        /// Returns a list with GuardianProfileTable objects.
        /// </summary>
        /// <returns>A generics List with the GuardianProfileTable objects.</returns>
        public static GuardianProfileTableList GetListByReligionCode(short ReligionCode)
        {
            GuardianProfileTableList tempList = new GuardianProfileTableList();
            using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sis.dbconn"].ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("sprocGuardianProfileTableSelectListByReligionCode", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;
                    myCommand.Parameters.AddWithValue("@religionCode", ReligionCode);
                    myConnection.Open();
                    using (SqlDataReader myReader = myCommand.ExecuteReader())
                    {
                        if (myReader.HasRows)
                        {
                            while (myReader.Read())
                            {
                                tempList.Add(FillDataRecord(myReader));
                            }
                        }
                        myReader.Close();
                    }
                }
                return tempList;
            }
        }

        /// <summary>
        /// Returns a list with GuardianProfileTable objects.
        /// </summary>
        /// <returns>A generics List with the GuardianProfileTable objects.</returns>
        public static GuardianProfileTableList GetListByUserAccountKey(int UserAccountKey)
        {
            GuardianProfileTableList tempList = new GuardianProfileTableList();
            using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sis.dbconn"].ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("sprocGuardianProfileTableSelectListByUserAccountKey", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;
                    myCommand.Parameters.AddWithValue("@userAccountKey", UserAccountKey);
                    myConnection.Open();
                    using (SqlDataReader myReader = myCommand.ExecuteReader())
                    {
                        if (myReader.HasRows)
                        {
                            while (myReader.Read())
                            {
                                tempList.Add(FillDataRecord(myReader));
                            }
                        }
                        myReader.Close();
                    }
                }
                return tempList;
            }
        }

        /// <summary>
        /// Saves a GuardianProfileTable in the database.
        /// </summary>
        /// <param name="myGuardianProfileTable">The GuardianProfileTable instance to save.</param>
        /// <returns>The new GuardianProfileKey if the GuardianProfileTable is new in the database or the existing GuardianProfileKey when an item was updated.</returns>
        public static int Save(GuardianProfileTable myGuardianProfileTable)
        {
            int result = 0;
            using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sis.dbconn"].ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("sprocGuardianProfileTableInsertUpdateSingleItem", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    if (myGuardianProfileTable.GuardianProfileKey == -1)
                    {
                        myCommand.Parameters.AddWithValue("@guardianProfileKey", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@guardianProfileKey", myGuardianProfileTable.GuardianProfileKey);
                    }
                    if (myGuardianProfileTable.UserAccountKey < 0)
                    {
                        myCommand.Parameters.AddWithValue("@userAccountKey", 0);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@userAccountKey", myGuardianProfileTable.UserAccountKey);
                    }
                    if (string.IsNullOrEmpty(myGuardianProfileTable.FirstName))
                    {
                        myCommand.Parameters.AddWithValue("@firstName", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@firstName", myGuardianProfileTable.FirstName);
                    }
                    if (string.IsNullOrEmpty(myGuardianProfileTable.LastName))
                    {
                        myCommand.Parameters.AddWithValue("@lastName", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@lastName", myGuardianProfileTable.LastName);
                    }
                    if (string.IsNullOrEmpty(myGuardianProfileTable.OtherName))
                    {
                        myCommand.Parameters.AddWithValue("@otherName", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@otherName", myGuardianProfileTable.OtherName);
                    }
                    if (string.IsNullOrEmpty(myGuardianProfileTable.Gender))
                    {
                        myCommand.Parameters.AddWithValue("@Gender", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@Gender", myGuardianProfileTable.Gender);
                    }
                    if (myGuardianProfileTable.DateOfBirth == null)
                    {
                        myCommand.Parameters.AddWithValue("@dateOfBirth", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@dateOfBirth", myGuardianProfileTable.DateOfBirth);
                    }
                    if (string.IsNullOrEmpty(myGuardianProfileTable.HighestEducation))
                    {
                        myCommand.Parameters.AddWithValue("@HighestEducation", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@HighestEducation", myGuardianProfileTable.HighestEducation);
                    }
                    if (string.IsNullOrEmpty(myGuardianProfileTable.Occupation))
                    {
                        myCommand.Parameters.AddWithValue("@Occupation", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@Occupation", myGuardianProfileTable.Occupation);
                    }
                    if (string.IsNullOrEmpty(myGuardianProfileTable.Designation))
                    {
                        myCommand.Parameters.AddWithValue("@Designation", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@Designation", myGuardianProfileTable.Designation);
                    }
                    if (string.IsNullOrEmpty(myGuardianProfileTable.CompanyName))
                    {
                        myCommand.Parameters.AddWithValue("@CompanyName", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@CompanyName", myGuardianProfileTable.CompanyName);
                    }
                    if (string.IsNullOrEmpty(myGuardianProfileTable.CompanyIndustry))
                    {
                        myCommand.Parameters.AddWithValue("@CompanyIndustry", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@CompanyIndustry", myGuardianProfileTable.CompanyIndustry);
                    }
                    if (myGuardianProfileTable.CompanySize == -1)
                    {
                        myCommand.Parameters.AddWithValue("@CompanySize", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@CompanySize", myGuardianProfileTable.CompanySize);
                    }
                    if (myGuardianProfileTable.AnnualGrossIncome < 0)
                    {
                        myCommand.Parameters.AddWithValue("@AnnualGrossIncome", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@AnnualGrossIncome", myGuardianProfileTable.AnnualGrossIncome);
                    }
                    if (myGuardianProfileTable.AnnualGrossIncomeCurrencyCode < 0)
                    {
                        myCommand.Parameters.AddWithValue("@AnnualGrossIncomeCurrencyCode", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@AnnualGrossIncomeCurrencyCode", myGuardianProfileTable.AnnualGrossIncomeCurrencyCode);
                    }
                    if (myGuardianProfileTable.BloodGroupCode < 0)
                    {
                        myCommand.Parameters.AddWithValue("@bloodGroupCode", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@bloodGroupCode", myGuardianProfileTable.BloodGroupCode);
                    }
                    if (myGuardianProfileTable.MartialStatusCode < 0)
                    {
                        myCommand.Parameters.AddWithValue("@martialStatusCode", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@martialStatusCode", myGuardianProfileTable.MartialStatusCode);
                    }
                    if (myGuardianProfileTable.RaceCode < 0)
                    {
                        myCommand.Parameters.AddWithValue("@raceCode", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@raceCode", myGuardianProfileTable.RaceCode);
                    }
                    if (myGuardianProfileTable.ReligionCode < 0)
                    {
                        myCommand.Parameters.AddWithValue("@religionCode", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@religionCode", myGuardianProfileTable.ReligionCode);
                    }
                    if (myGuardianProfileTable.NationalityCode < 0)
                    {
                        myCommand.Parameters.AddWithValue("@nationalityCode", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@nationalityCode", myGuardianProfileTable.NationalityCode);
                    }
                    if (string.IsNullOrEmpty(myGuardianProfileTable.NRICNumber))
                    {
                        myCommand.Parameters.AddWithValue("@nRICNumber", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@nRICNumber", myGuardianProfileTable.NRICNumber);
                    }
                    if (myGuardianProfileTable.DrivingLicenceType < 0)
                    {
                        myCommand.Parameters.AddWithValue("@drivingLicenceType", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@drivingLicenceType", myGuardianProfileTable.DrivingLicenceType);
                    }
                    if (string.IsNullOrEmpty(myGuardianProfileTable.DrivingLicenseNumber))
                    {
                        myCommand.Parameters.AddWithValue("@drivingLicenseNumber", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@drivingLicenseNumber", myGuardianProfileTable.DrivingLicenseNumber);
                    }
                    if (myGuardianProfileTable.TravelDocumentType < 0)
                    {
                        myCommand.Parameters.AddWithValue("@travelDocumentType", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@travelDocumentType", myGuardianProfileTable.TravelDocumentType);
                    }
                    if (string.IsNullOrEmpty(myGuardianProfileTable.TravelDocumentNumber))
                    {
                        myCommand.Parameters.AddWithValue("@travelDocumentNumber", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@travelDocumentNumber", myGuardianProfileTable.TravelDocumentNumber);
                    }
                    if (string.IsNullOrEmpty(myGuardianProfileTable.WebSiteUrl))
                    {
                        myCommand.Parameters.AddWithValue("@webSiteUrl", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@webSiteUrl", myGuardianProfileTable.WebSiteUrl);
                    }
                    if (myGuardianProfileTable.Status < 0)
                    {
                        myCommand.Parameters.AddWithValue("@status", DBNull.Value);
                    }
                    else
                    {
                        myCommand.Parameters.AddWithValue("@status", myGuardianProfileTable.Status);
                    }
                    //if (myGuardianProfileTable.CreatedDateTime == null)
                    //{
                    //    myCommand.Parameters.AddWithValue("@createdDateTime", DBNull.Value);
                    //}
                    //else
                    //{
                    //    myCommand.Parameters.AddWithValue("@createdDateTime", myGuardianProfileTable.CreatedDateTime);
                    //}
                    //if (myGuardianProfileTable.ModifiedDateTime == null)
                    //{
                    //    myCommand.Parameters.AddWithValue("@modifiedDateTime", DBNull.Value);
                    //}
                    //else
                    //{
                    //    myCommand.Parameters.AddWithValue("@modifiedDateTime", myGuardianProfileTable.ModifiedDateTime);
                    //}

                    DbParameter returnValue;
                    returnValue = myCommand.CreateParameter();
                    returnValue.Direction = ParameterDirection.ReturnValue;
                    myCommand.Parameters.Add(returnValue);

                    myConnection.Open();
                    myCommand.ExecuteNonQuery();
                    result = Convert.ToInt32(returnValue.Value);
                    myConnection.Close();
                }
            }
            return result;
        }

        /// <summary>
        /// Deletes a GuardianProfileTable from the database.
        /// </summary>
        /// <param name="guardianProfileKey">The GuardianProfileKey of the GuardianProfileTable to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        public static bool Delete(int guardianProfileKey)
        {
            int result = 0;
            using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sis.dbconn"].ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("sprocGuardianProfileTableDeleteSingleItem", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    myCommand.Parameters.AddWithValue("@guardianProfileKey", guardianProfileKey);
                    myConnection.Open();
                    result = myCommand.ExecuteNonQuery();
                    myConnection.Close();
                }
            }
            return result > 0;
        }

        #endregion

        /// <summary>
        /// Initializes a new instance of the GuardianProfileTable class and fills it with the data fom the IDataRecord.
        /// </summary>
        private static GuardianProfileTable FillDataRecord(IDataRecord myDataRecord)
        {
            GuardianProfileTable myGuardianProfileTable = new GuardianProfileTable();
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("GuardianProfileKey")))
            {
                myGuardianProfileTable.GuardianProfileKey = myDataRecord.GetInt32(myDataRecord.GetOrdinal("GuardianProfileKey"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("UserAccountKey")))
            {
                myGuardianProfileTable.UserAccountKey = myDataRecord.GetInt32(myDataRecord.GetOrdinal("UserAccountKey"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("FirstName")))
            {
                myGuardianProfileTable.FirstName = myDataRecord.GetString(myDataRecord.GetOrdinal("FirstName"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("LastName")))
            {
                myGuardianProfileTable.LastName = myDataRecord.GetString(myDataRecord.GetOrdinal("LastName"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("OtherName")))
            {
                myGuardianProfileTable.OtherName = myDataRecord.GetString(myDataRecord.GetOrdinal("OtherName"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("Gender")))
            {
                myGuardianProfileTable.Gender = myDataRecord.GetString(myDataRecord.GetOrdinal("Gender"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("DateOfBirth")))
            {
                myGuardianProfileTable.DateOfBirth = myDataRecord.GetDateTime(myDataRecord.GetOrdinal("DateOfBirth"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("HighestEducation")))
            {
                myGuardianProfileTable.HighestEducation = myDataRecord.GetString(myDataRecord.GetOrdinal("HighestEducation"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("Occupation")))
            {
                myGuardianProfileTable.Occupation = myDataRecord.GetString(myDataRecord.GetOrdinal("Occupation"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("Designation")))
            {
                myGuardianProfileTable.Designation = myDataRecord.GetString(myDataRecord.GetOrdinal("Designation"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("CompanyName")))
            {
                myGuardianProfileTable.CompanyName = myDataRecord.GetString(myDataRecord.GetOrdinal("CompanyName"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("CompanyIndustry")))
            {
                myGuardianProfileTable.CompanyIndustry = myDataRecord.GetString(myDataRecord.GetOrdinal("CompanyIndustry"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("CompanySize")))
            {
                myGuardianProfileTable.CompanySize = myDataRecord.GetInt16(myDataRecord.GetOrdinal("CompanySize"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("AnnualGrossIncome")))
            {
                myGuardianProfileTable.AnnualGrossIncome = myDataRecord.GetDecimal(myDataRecord.GetOrdinal("AnnualGrossIncome"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("AnnualGrossIncomeCurrencyCode")))
            {
                myGuardianProfileTable.AnnualGrossIncomeCurrencyCode = myDataRecord.GetInt16(myDataRecord.GetOrdinal("AnnualGrossIncomeCurrencyCode"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("BloodGroupCode")))
            {
                myGuardianProfileTable.BloodGroupCode = myDataRecord.GetInt16(myDataRecord.GetOrdinal("BloodGroupCode"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("MartialStatusCode")))
            {
                myGuardianProfileTable.MartialStatusCode = myDataRecord.GetInt16(myDataRecord.GetOrdinal("MartialStatusCode"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("RaceCode")))
            {
                myGuardianProfileTable.RaceCode = myDataRecord.GetInt16(myDataRecord.GetOrdinal("RaceCode"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("ReligionCode")))
            {
                myGuardianProfileTable.ReligionCode = myDataRecord.GetInt16(myDataRecord.GetOrdinal("ReligionCode"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("NationalityCode")))
            {
                myGuardianProfileTable.NationalityCode = myDataRecord.GetInt16(myDataRecord.GetOrdinal("NationalityCode"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("NRICNumber")))
            {
                myGuardianProfileTable.NRICNumber = myDataRecord.GetString(myDataRecord.GetOrdinal("NRICNumber"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("DrivingLicenceType")))
            {
                myGuardianProfileTable.DrivingLicenceType = myDataRecord.GetInt16(myDataRecord.GetOrdinal("DrivingLicenceType"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("DrivingLicenseNumber")))
            {
                myGuardianProfileTable.DrivingLicenseNumber = myDataRecord.GetString(myDataRecord.GetOrdinal("DrivingLicenseNumber"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("TravelDocumentType")))
            {
                myGuardianProfileTable.TravelDocumentType = myDataRecord.GetInt16(myDataRecord.GetOrdinal("TravelDocumentType"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("TravelDocumentNumber")))
            {
                myGuardianProfileTable.TravelDocumentNumber = myDataRecord.GetString(myDataRecord.GetOrdinal("TravelDocumentNumber"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("WebSiteUrl")))
            {
                myGuardianProfileTable.WebSiteUrl = myDataRecord.GetString(myDataRecord.GetOrdinal("WebSiteUrl"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("Status")))
            {
                myGuardianProfileTable.Status = myDataRecord.GetInt16(myDataRecord.GetOrdinal("Status"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("CreatedDateTime")))
            {
                myGuardianProfileTable.CreatedDateTime = myDataRecord.GetDateTime(myDataRecord.GetOrdinal("CreatedDateTime"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("ModifiedDateTime")))
            {
                myGuardianProfileTable.ModifiedDateTime = myDataRecord.GetDateTime(myDataRecord.GetOrdinal("ModifiedDateTime"));
            }
            return myGuardianProfileTable;
        }
    }

}
